/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package matching.triple;

import matching.Restriction;
import matching.xml.MatchElements;
import ontology.Ontology;
import org.jdom.Element;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLDataProperty;

/**
 *
 * @author livia
 */
public class ClassTriple implements Triple {

    public OWLClass element;
    public Restriction restriction;
    public Ontology onto;

    public ClassTriple(OWLClass e, Restriction r, Ontology onto) {
       element=e;
       restriction=r;
       this.onto = onto;
    }

    @Override
    public String getElement() {
        return element.getNNF().toString();
    }

    @Override
    public boolean equals(Triple t) {
        return false;
    }

    @Override
    public boolean isClass() {
        return true;
    }

	
    public Restriction getRestriction() {
            return restriction;
    }

    public OWLClass getContext() {
            return null;
    }

    public String toString(){
            return "element:"+element+" restriction:"+restriction;
    }

    public String[] toArray(){
        String r;
        if(restriction!=null){
            r=restriction.toString();
        }
        else{ r="";}
        return new String[] {element.toString(), "", r};
    }

     public  Element toElementXML(String type){
        Element triple = new Element(type);
        triple.addContent(new Element(MatchElements.element).addContent(element.toString()));
        if(restriction!=null){
            Element rest = new Element(MatchElements.restriction);
            rest.addContent(new Element(MatchElements.attribute).addContent(restriction.atributte.toString()));
            rest.addContent(new Element(MatchElements.value).addContent(restriction.value));
        }
        return triple;
    }

    public Ontology getOnto() {
       return onto;
    }

    public void setRestriction(Restriction r){
        if(onto.getDataPropertiesOf(element.toString()).contains(r.atributte)){
            restriction = r;
        }
    }

     public void setRestriction(String atributte, String value){
         OWLDataProperty atr = onto.getDataProperty(atributte);
         if(atr!=null) restriction = new Restriction(atr, value);
        
     }
}
